package com.svms.save.controller;

import com.svms.save.config.SvmsSaveConfig;
import com.svms.save.entitys.SvdaYhb;
import com.svms.save.services.IndexService;
import com.svms.save.services.SvdaYhService;
import com.svms.save.vo.GroupByVo;
import com.svms.save.vo.ResultVo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

@Controller
public class IndexController {
    @Autowired
    private SvmsSaveConfig config;
    @Autowired
    private IndexService indexManager;
    @Autowired
    private SvdaYhService yhManager;
    
    Logger log = LoggerFactory.getLogger(IndexController.class);
    @RequestMapping("/indexPage")
    public String indexPage(Model model, HttpServletRequest request) {
        SvdaYhb yh = yhManager.getCurrentUser(request);
    	model.addAttribute("config",config);
    	model.addAttribute("user",yh);
        return "/framepage";
    }
    @RequestMapping("/index")
    public String index(Model model, HttpServletRequest request) {
        model.addAttribute("config",config);
        return "/index";
    }
    @RequestMapping("/ztqkList")
    @ResponseBody
    public ResultVo<List<GroupByVo>> ztqk(){
    	ResultVo<List<GroupByVo>> res = null;
    	try {
			List<GroupByVo> list = indexManager.ztqkCount();
			res = ResultVo.success("", list);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			res = ResultVo.systemError("服务异常。", new ArrayList<>());
			log.error("系统错误！",e);
		}
    	return res;
    }
    @RequestMapping("/gdwqkList")
    @ResponseBody
    public ResultVo<List<GroupByVo>> gdwqk(){
    	ResultVo<List<GroupByVo>> res = null;
    	try {
			List<GroupByVo> list = indexManager.gdwCount();
			res = ResultVo.success("", list);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			res = ResultVo.systemError("服务异常。", new ArrayList<>());
			log.error("系统错误！",e);
		}
    	return res;
    }
    
    @RequestMapping("/glechars")
    @ResponseBody
    public ResultVo<List<GroupByVo>> glechars(){
    	ResultVo<List<GroupByVo>> res = null;
    	try {
			List<GroupByVo> list = indexManager.glechars();
			res = ResultVo.success("", list);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			res = ResultVo.systemError("服务异常。", new ArrayList<>());
			log.error("系统错误！",e);
		}
    	return res;
    }
}
